package com.aptech.action;

import java.util.*;

import net.sf.jasperreports.engine.JasperCompileManager;

import org.apache.struts2.ServletActionContext;
import org.jfree.data.*;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.*;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPosition;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.*;

import java.awt.Font;
import java.awt.geom.Ellipse2D.Float;
import java.io.File;

import org.jfree.chart.title.TextTitle;
import org.jfree.chart.title.LegendTitle;

import com.aptech.bean.PeopleBean;
import com.opensymphony.xwork2.ActionSupport;

public class JasperAction extends ActionSupport{

	

	private static final long serialVersionUID = 1L;

    private List<PeopleBean> myList;

    public String execute() throws Exception {
        //添加数据
        PeopleBean p1=new PeopleBean("长沙", new Integer(9), "李化", "天洒路");
        PeopleBean p2=new PeopleBean("长沙", new Integer(22), "王小样", "呆小路564");
        PeopleBean p3=new PeopleBean("南昌", new Integer(23), "王奸可", "小顺路");
        PeopleBean p4=new PeopleBean("南昌", new Integer(32), "李洒", "顺濉路");
        PeopleBean p5=new PeopleBean("武汉", new Integer(39), "张中尖", "天洒路");
        PeopleBean p6=new PeopleBean("武汉", new Integer(35), "陈主宁", "天河路５６４");
        myList = new ArrayList<PeopleBean>();
        myList.add(p1);
        myList.add(p2);
        myList.add(p3);
        myList.add(p4);
        myList.add(p5);
        myList.add(p6);

        try {   
            String reportSource;   
            reportSource = ServletActionContext.getServletContext()   
                    .getRealPath("/jasper/jasper_template.jrxml");   
            File parent = new File(reportSource).getParentFile();   
            JasperCompileManager.compileReportToFile(reportSource, new File(   
                    parent, "compiled_jasper_template.jasper")   
                    .getAbsolutePath());   
        } catch (Exception e) {   
            e.printStackTrace();   
            return ERROR;   
        }   

        return SUCCESS;
    }

    public List getMyList() {
        return myList;
    }

}
